package com.ruoyi.baoming.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.baoming.domain.Ethnicity;
import com.ruoyi.baoming.service.IEthnicityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 民族信息Controller
 * 
 * @author xiaosong
 * @date 2024-11-20
 */
@Api(tags = "基础管理-民族信息")
@RestController
@RequestMapping("/baoming/ethnicity")
public class EthnicityController extends BaseController
{
    @Autowired
    private IEthnicityService ethnicityService;

    /**
     * 查询民族信息列表
     */
    @PreAuthorize("@ss.hasPermi('baoming:ethnicity:list')")
    @ApiOperation("民族信息管理 - 分页查询列表")
    @GetMapping("/list")
    public TableDataInfo list(Ethnicity ethnicity)
    {
        startPage();
        List<Ethnicity> list = ethnicityService.selectEthnicityList(ethnicity);
        return getDataTable(list);
    }

    /**
     * 导出民族信息列表
     */
    @PreAuthorize("@ss.hasPermi('baoming:ethnicity:export')")
    @Log(title = "民族信息", businessType = BusinessType.EXPORT)
    @ApiOperation("民族信息管理 - 导出数据")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ethnicity ethnicity)
    {
        List<Ethnicity> list = ethnicityService.selectEthnicityList(ethnicity);
        ExcelUtil<Ethnicity> util = new ExcelUtil<Ethnicity>(Ethnicity.class);
        util.exportExcel(response, list, "民族信息数据");
    }

    /**
     * 获取民族信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:ethnicity:query')")
    @ApiOperation("民族信息管理 - 根据ID获取详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ethnicityService.selectEthnicityById(id));
    }

    /**
     * 新增民族信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:ethnicity:add')")
    @Log(title = "民族信息", businessType = BusinessType.INSERT)
    @ApiOperation("民族信息管理 - 新增数据")
    @PostMapping
    public AjaxResult add(@RequestBody Ethnicity ethnicity)
    {
        return toAjax(ethnicityService.insertEthnicity(ethnicity));
    }

    /**
     * 修改民族信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:ethnicity:edit')")
    @Log(title = "民族信息", businessType = BusinessType.UPDATE)
    @ApiOperation("民族信息管理 - 修改数据")
    @PutMapping
    public AjaxResult edit(@RequestBody Ethnicity ethnicity)
    {
        return toAjax(ethnicityService.updateEthnicity(ethnicity));
    }

    /**
     * 删除民族信息
     */
    @PreAuthorize("@ss.hasPermi('baoming:ethnicity:remove')")
    @Log(title = "民族信息", businessType = BusinessType.DELETE)
	@ApiOperation("民族信息管理 - 删除数据")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ethnicityService.deleteEthnicityByIds(ids));
    }
}
